<template>
    <view>
		<view>
			<table-title content="委托书文档上传"></table-title>
			<view>
			    <small-title content="基本资料"></small-title>
			    <view class="item-table">
			        <view-item name="申请人" :value="userName"></view-item>
			        <view-item name="手机号码" :value="userPhone"></view-item>
			        <view-item name="租户名称" :value="company"></view-item>
			        <view-item name="楼盘" :isLast="true" :value="building"></view-item>
			    </view>
			</view>
			<view style="margin-bottom: 100rpx;">
			    <small-title content="委托人信息"></small-title>
			    <view class="item-table">
			        <input-item typeMsg="姓名"></input-item>
			        <input-item typeMsg="身份证" :isLast="true"></input-item>
			    </view>
			    <view style="display: flex;margin-top: 10rpx;">
			        <view class="picture-block">
			            <image v-if="hasAdd[0]" src="@/static/delete-logo.svg" class="wrong-logo"
							@click="deletePicture(0)"></image>
			            <image v-if="!hasAdd[0]" src="@/static/add-logo.svg" class="picture-style" @click="addPicture(0)"></image>
						<image v-if="hasAdd[0]" :src="imageUrl[0]" class="picture-style" @click="previewPicture(0)"></image>
						<view class="picture-note">身份证正面</view>
						<yq-avatar @upload="myUpload" ref="avatar"></yq-avatar>
			        </view>
			        <view class="picture-block">
			            <image v-if="hasAdd[1]" src="@/static/delete-logo.svg" class="wrong-logo"
			        		@click="deletePicture(1)"></image>
			            <image v-if="!hasAdd[1]" src="@/static/add-logo.svg" class="picture-style" @click="addPicture(1)"></image>
			        	<image v-if="hasAdd[1]" :src="imageUrl[1]" class="picture-style" @click="previewPicture(1)"></image>
			        	<view class="picture-note">身份证反面</view>
			        	<yq-avatar @upload="myUpload" ref="avatar"></yq-avatar>
			        </view>
			        <view class="picture-block">
			            <image v-if="hasAdd[2]" src="@/static/delete-logo.svg" class="wrong-logo"
			        		@click="deletePicture(2)"></image>
			            <image v-if="!hasAdd[2]" src="@/static/add-logo.svg" class="picture-style" @click="addPicture(2)"></image>
			        	<image v-if="hasAdd[2]" :src="imageUrl[2]" class="picture-style" @click="previewPicture(2)"></image>
			        	<view class="picture-note">委托书</view>
			        	<yq-avatar @upload="myUpload" ref="avatar"></yq-avatar>
			        </view>
			    </view>
			</view>
			<button class="confirm-button" @click="confirm">确认</button>
			<view style="height: 200rpx;"></view>
		</view>
		<u-tabbar v-model="current" :list="list" :before-switch="clickTabbar"></u-tabbar>
    </view>
</template>

<script>
    export default{
        data() {
            return {
                userName: '李阳',
                userPhone: '18705015193',
                company: '福建海峡科技有限公司',
                building: '福建八闽大厦',
				hasAdd: [false,false,false],
                imageUrl: ['../../../static/add-logo.svg','../../../static/add-logo.svg',
					'../../../static/add-logo.svg'],
				list: [
					{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						customIcon: false,
					},
					{
						iconPath: "photo",
						selectedIconPath: "photo-fill",
						text: '管家',
						customIcon: false,
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '发现',
						customIcon: false,
					},
					{
						iconPath: "play-right",
						selectedIconPath: "play-right-fill",
						text: '消息',
						count: 23,
						customIcon: false,
					},
					{
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
					},
				],
				current: 0
            }
        },
        methods: {
			myUpload(rsp) {
			    this.$set(this.imageUrl, rsp.index, rsp.path);
			},
			addPicture(index) {
				let hasAddTmp = [...this.hasAdd]
				hasAddTmp[index] = true
				this.hasAdd = hasAddTmp
			    this.$refs.avatar.fChooseImg(index,{
			        selWidth: "640upx", selHeight: "400upx",
			        expWidth: '640upx', expHeight: '400upx'
			    });
			},
            deletePicture(e){
				let hasAddTmp = [...this.hasAdd]
                let imgTmp = [...this.imageUrl]
                imgTmp[e] = ''
				hasAddTmp[e] = !hasAddTmp[e]
				this.hasAdd = hasAddTmp
                this.imageUrl = imgTmp
            },
			previewPicture(e){
				console.log(this.imageUrl.slice(e,e+1))
				uni.previewImage({
					urls:this.imageUrl.slice(e,e+1),
					longPressActions:{
						itemList:['发送给朋友','保存图片','收藏']
					}
				})
			},
			confirm(){
				uni.redirectTo({
					url:'../details/details'
				})
			},
			clickTabbar(index) {
				switch(index){
					case 0:
						console.log('首页')
						uni.redirectTo({
							url:'/pages/home/home'
						})
						return true
						break
					case 1:
						console.log('管家')
						return true
						break
					case 2:
						console.log('发现')
						return true
						break
					case 3:
						console.log('消息')
						uni.redirectTo({
							url:'/pages/systemAnnoucement/list/list'
						})
						return true
						break
					case 4:
						console.log('我的')
						uni.navigateTo({
							url:'/pages/myPage/myPage'
						})
						return true
						break
				}
			}
        },
    }
</script>

<style>
	.item-table{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.picture-part{
		display: flex;
		margin: 0 0 50rpx 0;
		font-size: 100rpx;
		font-weight: 200;
		align-items: center;
		justify-content: center;	
		width: 170rpx;
		height: 170rpx;
		border: dashed 1rpx #000000;
	}
	.picture-style{
		width: 170rpx;
		height: 170rpx;
		margin: 0 0 10rpx 0rpx;
	}
	.picture-note{
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
	}
	.picture-block{
		display: flex;
		flex-direction: column;
		justify-content: center;
		margin-left: 60rpx;
	}
	.confirm-button{
		background-color: #007AFF;
		color: #FFFFFF;
		width: 650rpx;
	}
	.wrong-logo{
		width: 40rpx;
		height: 40rpx;
		margin-bottom: -40rpx;
		margin-left: 130rpx;
		z-index: 980;
		background-color: #555555
	}
</style>